<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
// classe de base, avec ses membres et ses méthodes
class Gallerymgr extends Controller{

	function Gallerymgr() {
	   parent::Controller();
	   $this->load->model('gallery_model');
	}

    function index()
    {
        $output=array();
    	$this->load->view('/admin/gallerymgr/index.html.php',$output);
    }
   
    //ajax call
    function listgals()
    {
        $output['galleries']=$this->gallery_model->getAllGals();
        $this->load->view('/admin/gallerymgr/index_jx_listgals.html.php',$output);
    }
   
    //ajax call
    function addgal($galname)
    {
        $this->gallery_model->addGal($galname);
    }
    
    //ajax call
    function delgal($galname)
    {
        $this->gallery_model->delGal($galname);
    }
    
    function gallery($gallery)
    {
        //$output['gallerydata']=$this->gallery_model->getGalleryData($gallery);
        $output['galname']=$gallery;
        $output['div_header']    = $this->load->view('/admin/header.html.php',$output,true);
        $output['js_header']     = $this->load->view('/admin/gallerymgr/gallery.js.php',$output,true);
        $this->load->view('/admin/gallerymgr/gallery.html.php',$output);
    }
    
    function listimgs($gallery)
    {
        $this->load->helper('javascript');
        $output['gallerydata']=$this->gallery_model->getGalleryData($gallery);
        $this->load->view('/admin/gallerymgr/gallery_jx_listimgs.html.php',$output);
    }
   
    //ajax post call
    //order,tags,caption,filename
    function savechanges($gallery)
    {
        $newdata=array();
        $newdata['main']['name']=$this->input->post('name');
        $newdata['main']['template']=$this->input->post('template');
        $lines=explode("\n",substr(stripslashes($this->input->post('images_infos')),0,-1));
        foreach ($lines as $line)
        {
            list($order,$tags,$caption,$filename)=explode('||',$line);
            $newdata['images'][$filename] = array ( 'order'=> $order, 'caption' => $caption,'filename'=>$filename,'tags'=>$tags );
        }
        echo $this->gallery_model->saveGalleryData($gallery,$newdata);
    }
   
   //img upload
   //ajax call
   function uploadimg($gallery)
   {
        $this->load->helper('javascript');
        $answ = $this->gallery_model->addImage($gallery);
        $msg=array();
        if ($answ===true) {
        } else {
            $msg['err']=$answ;
        }
        echo buildJson($msg);
   }
   
   //del image
   //ajax call
   function delimg($gallery)
   {
        return $this->gallery_model->delImage($gallery,$this->input->post('filename'));
   }
   
   
}

?>
